<template>
  <div class="index">
  	<div class="sreePublic">
  		<div id="" style="text-align: center;">
  			<em class="iconfont" @click="vfun_back">&#xe61f;</em>
  		</div>
		{{vue_invoice_title}}
  	</div>
  	<div>
  		<div class="delivery">
  			<p>{{vue_invoiceType}}</p>
  			<ul>
  				<li>
  					<span>发票抬头：</span>
  					<input v-model="MemberInvoiceData.invoiceTitle" />
  				</li>
  				<li>
  					<span>发票内容：</span>
  					<input v-model="MemberInvoiceData.invoiceContent" />
  				</li>
  				<li>
  					<span>纳税人识别号：</span>
  					<input v-model="MemberInvoiceData.invoiceTaxId" />
  				</li>
  				<li>
  					<span>地址：</span>
  					<input v-model="MemberInvoiceData.invoiceAddress"/>
  				</li>
  				<li>
  					<span>电话：</span>
  					<input v-model="MemberInvoiceData.invoicePhone"/>
  				</li>
  				<li>
  					<span>开户银行：</span>
  					<input v-model="MemberInvoiceData.invoiceBank"/>
  				</li>
  				<li>
  					<span>银行账号：</span>
  					<input v-model="MemberInvoiceData.invoiceAccount"/>
  				</li>
  			</ul>
  		</div>
  		
	    <div class="footer">
	    	<a @click="save" :class="{acvivebtn:vue_btn}">保存</a>
	    </div>
	   
	</div>
  </div>
</template>

<script>
	import { MessageBox } from 'mint-ui';
	import { Toast } from 'mint-ui';  //引入弹框
export default {
  name: 'addInvoiceInfo',
  data () {
    return {
    	vue_btn:false,
    	vue_invoice_title:'新增发票信息',
    	vue_invoiceType:'',			//发票类型
    	MemberInvoiceData:{
    		invoiceContent:'商品明细'
    	},
    }
  },
  methods:{
  	vFun_invoice_info(code){
  		this.axios({
  			method:'GET',
  			url:'/v3/member/invoices/'+code,
  			data:{}
  		}).then(res=>{
  			this.MemberInvoiceData=res.data;
  		}).catch(err=>{
  			
  		})
  	},
	save(){
		this.vue_btn=true;
//		if (this.deliveryContact=='') {
//			MessageBox('提示', '请填写收货人');
//			return false;
//		}
//		if (this.deliveryPhone=='') {
//			MessageBox('提示', '请填写联系电话');
//			return false;
//		}else{
//			let str=this.Public.rules.phone;
//			if(str.test(this.deliveryPhone) != true){
//				MessageBox('提示', '请填写正确的联系电话');
//				return false;
//			} 
//		}
//		if (this.deliveryAddress=='') {
//			MessageBox('提示', '请填写详细地址');
//			return false;
//		}
//		
//		if (this.single) {
//			this.deliveryDefault='1'
//		}else{
//			this.deliveryDefault='0'
//		}
		if(localStorage.getItem('updateInvoiceCode')){
			this.axios({
				method:'PUT',
				url:"/v3/member/invoices/"+localStorage.getItem('updateInvoiceCode'),
				data:{
					"memberCode":localStorage.getItem("memberCode"),
					"invoiceType":localStorage.getItem("invoiceType"),
					"invoiceTitle":this.MemberInvoiceData.invoiceTitle,
					"invoiceContent":this.MemberInvoiceData.invoiceContent,
					"invoiceTaxId":this.MemberInvoiceData.invoiceTaxId, 
					"invoiceAddress ":this.MemberInvoiceData.invoiceAddress ,
					"invoicePhone":this.MemberInvoiceData.invoicePhone,
					"invoiceBank":this.MemberInvoiceData.invoiceBank,
					"invoiceAccount":this.MemberInvoiceData.invoiceAccount,
				}
			}).then(res=>{
				this.Public.vFun_openSuccess('修改成功');
				this.$router.go(-1);
				localStorage.removeItem('updateInvoiceCode');
			}).catch(err=>{
				this.Public.vFun_openError(err.response.data);
				this.vue_btn=false;
			})
		}else{
			this.deliveryArea=this.addressProvince+this.addressCity+this.addressXian;
			this.axios({
					method: 'POST',
					url: "/v3/member/invoices",
					data:{
						"memberCode":localStorage.getItem("memberCode"),
						"invoiceType":localStorage.getItem("invoiceType"),
						"invoiceTitle":this.MemberInvoiceData.invoiceTitle,
						"invoiceContent":this.MemberInvoiceData.invoiceContent,
						"invoiceTaxId":this.MemberInvoiceData.invoiceTaxId, 
						"invoiceAddress ":this.MemberInvoiceData.invoiceAddress ,
						"invoicePhone":this.MemberInvoiceData.invoicePhone,
						"invoiceBank":this.MemberInvoiceData.invoiceBank,
						"invoiceAccount":this.MemberInvoiceData.invoiceAccount,
					}
					}).then((res) => {
						Toast({
						  message: '新增成功',
						  iconClass: 'fontSize iconfont icon-chenggong'
						});
	 						history.back();
						
					}).catch((err)=>{
						Toast({
						  message: err.response.data,
						  iconClass: 'fontSize iconfont icon-shibai'
						});
						this.vue_btn=false;
		  	});
		}
	},
  	vfun_back(){
  		history.back();
  	},
  },
  watch: {
      
  },
  activated(){
  	if(localStorage.getItem("invoiceType")=='2'){
  		this.vue_invoiceType='普通发票';
  	}else{
  		this.vue_invoiceType='增值税发票';
  	}
  },
    created(){
     if(localStorage.getItem('updateInvoiceCode')){
     	this.vue_invoice_title='修改发票信息';
     	this.vFun_invoice_info(localStorage.getItem('updateInvoiceCode'))
     }
    },
  mounted(){
  	if(localStorage.getItem("invoiceType")=='2'){
  		this.vue_invoiceType='普通发票';
  	}else{
  		this.vue_invoiceType='增值税发票';
  	}
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
*{
	transition: 0.2s;
}
h1, h2 {
  font-weight: normal;
}

ul {
  list-style-type: none;
  padding: 0;
}
.index{
	box-sizing: border-box;
	margin-bottom: 1.5rem;
}

.delivery{
	margin-top: 1.2rem;
}
.delivery p{
	text-align: center;
	background: #D2D3D9;
	height: 1rem;
	line-height: 1rem;
}
.delivery li{
	border-bottom: 1px solid #bbb;
	box-sizing: border-box;background: #fff;
	padding: 4% 6%;
	display: -webkit-box;
}
.delivery li:last-child{
	border-bottom:0;
}
.delivery span{
	display: block;
	width: auto;
}
.delivery input{
	display: block;
	border: 0;
	-webkit-box-flex: 1;
}
.footer{
	position: fixed;
	background: #fff;
	bottom: 0;
	width: 100%;
}
.footer a{
	display: block;
	width: 98%;
	margin-left: 1%;
	margin-bottom: 1%;
	color: #fff;
	text-align: center;
	height: 1.4rem;
	background: #D50B0A;
	line-height: 1.4rem;
	border-radius:4px ;
	 font-size: 16px;
}
.delivery .iconfont{
	float: right;
	color: #ccc;
	font-size: 14px;
}
.deliverytab{
	width: 10rem;
	height: 9rem;
}
.delivery-th{
	margin-top: 0.4rem;color: #D50B0A;
}
.delivery-th span:first-child{
	float: left;
	margin-left: 5%;
}
.delivery-th span:last-child{
	float: right;
	margin-right: 5%;
}
.acvivebtn{
	pointer-events: none;
}
</style>